// created by noellynch
// May 15, 2009

package com.sceneworker.passmonitor;

import javax.swing.Icon;

import com.acarter.composabletree.ComposableTreeNode;
import com.acarter.jmejtree.JMEJTreeIcon;
import com.jme.renderer.pass.Pass;
import com.jme.scene.PassNode;
import com.jme.scene.Spatial;

public class PassSpatialTreeNode implements ComposableTreeNode {

	public Object getChild(Object parent, int index) {
		if(parent instanceof Pass) {
			Pass		lcl_pass = (Pass)parent;
			if(index < lcl_pass.size()) {
				return lcl_pass.get(index);
			}
		}
		return null;
	}

	public int getChildCount(Object parent) {
		if(parent instanceof Pass) {
			Pass		lcl_pass = (Pass)parent;
			return lcl_pass.size();
		}
		
		return 0;
	}

	public int getChildIndex(Object parent, Object child) {
		if(parent instanceof Pass) {
			Pass		lcl_pass = (Pass)parent;
			for(int li_index = 0; li_index < lcl_pass.size(); li_index++) {
				if(lcl_pass.get(li_index) == child) {
					return li_index;
				}
			}
		}
		
		return -1;
	}

	public Icon getIcon(Object node) {
		return JMEJTreeIcon.getIcon().node;
	}

	public Class<?> getNodeClassType() {
		return Spatial.class;
	}

	public String getNodeText(Object node, boolean selected, boolean expanded,
			boolean leaf, int row, boolean hasFocus) {
		if(node instanceof Spatial) {
			return ((Spatial)node).getName();
		}
		return null;
	}

	public String getNodeToolTipText(Object node, boolean selected,
			boolean expanded, boolean leaf, int row, boolean hasFocus) {
		if(node instanceof Spatial) {
			return ((Spatial)node).getName();
		}
		
		return null;
	}

	public Object getParent(Object child) {
		return null;
	}

}
